package com.huipinche.test;
import com.huipinche.dao.bean.Journey;
import com.huipinche.dao.bean.User;
import com.huipinche.dao.impl.JourneyDaoimpl;
import com.huipinche.dao.impl.UserDaoimpl;
import com.huipinche.service.impl.*;
import com.huipinche.service.judgeJourneyService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.List;
import java.util.Scanner;
public class servicetest {
    User user1 = new User();
    User user2 = new User();
    Journey journey1=new Journey();
    Journey journey2=new Journey();
    Journey journey3=new Journey();
    /**
     * 初始化方法：
     *  初始化，给三个行程类的数值进行赋值
     */
    @Before
    public void init() throws ParseException {
        System.out.println("init...初始化2两个用户类和三个行程类");
        System.out.println("\n");

        //初始化两个行程变量
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1 = dateFormat.parse("2021-08-08 21:00:00");
        Date date2 = dateFormat.parse("2021-07-07 21:00:00");
        Date date3 = dateFormat.parse("2021-06-06 21:00:00");

        //初始化两个用户变量
        user1.setUser("lyh");
        user1.setPassword("123456");
        user1.setTel("18826681399");
        user1.setJfid(99);
        user1.setId(96);
        user2.setUser("xlj");
        user2.setPassword("666666");
        user2.setTel("666666");
        user2.setJfid(6);
        user2.setId(77);

        UserDaoimpl userDaoimpl =new UserDaoimpl();
        //写入第一个类
        userDaoimpl.insertUser(user1);
        //写入第二个类
        userDaoimpl.insertUser(user2);

        journey1.setJourneyflag(1);
        journey1.setStartadd("华南理工大学国际校区西北面");
        journey1.setEndadd("新造A1口");
        journey1.setTel("18826681399");
        journey1.setUid(96);
        journey1.setJourneytime(date1);

        journey2.setJourneyflag(0);
        journey2.setStartadd("新造A1口");
        journey2.setEndadd("华南理工大学国际校区西北面");
        journey2.setTel("18826681399");
        journey2.setUid(77);
        journey2.setJourneytime(date2);

        journey3.setJourneyflag(2);
        journey3.setStartadd("新造B1口");
        journey3.setEndadd("华南理工大学国际校区南面");
        journey3.setTel("18826681399");
        journey3.setUid(77);
        journey3.setJourneytime(date3);


        JourneyDaoimpl journeyDaoimpl = new JourneyDaoimpl();
        //在数据库中写入三个行程类
        journeyDaoimpl.insertJourney(journey1);
        journeyDaoimpl.insertJourney(journey2);
        journeyDaoimpl.insertJourney(journey3);
    }

    //找单服务的测试，思达那一条业务线
    @Test
    public void Journeytest() throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date3 = dateFormat.parse("2021-06-06 21:00:00");

        //通过服务层的接口，查看返回的数值
        mainJourneyServiceimpl mainJourneyServiceimpl =new mainJourneyServiceimpl();
        Journey[] journey =mainJourneyServiceimpl.mainJourney();
        System.out.print("查询所有订单"+journey[0].toString());
        System.out.println("\n");
        System.out.print("查询所有订单"+journey[1].toString());
        System.out.println("\n");
        System.out.print("查询所有订单"+journey[2].toString());
        System.out.println("\n");

        findJourneyServiceimpl findJourneyServiceimpl = new findJourneyServiceimpl();
        Journey[] journey1 = findJourneyServiceimpl.findJourneyByadd( "新造B1口");
        System.out.print("按目的地查询行程"+journey1[0].toString());
        System.out.println("\n");

        Journey[] journey2 = findJourneyServiceimpl.findJourneyBytime(date3);
        System.out.print("按时间查询行程"+journey2[0].toString());
        System.out.println("\n");


        judgeJourneyServiceimpl judgeJourneyServiceimpl= new judgeJourneyServiceimpl();
        Journey Journey=judgeJourneyServiceimpl.judgeJourneyService(1);
        System.out.print("id 为 1 的订单"+Journey.toString());
        System.out.println("\n");

        //3.断言  我断言这个结果是3
//        Assert.assertEquals(3,result);
    }


    //用户登录，注册，发起拼单的测试，超哥那一条业务线
    @Test
    public void Usertest(){
        System.out.println("已经存在俩用户，lyh，xlj,尝试使用 yc 用户登录，观察是否成功");
        //测试登录
        if (new loginUserServiceimpl().loginUserService("yc","123456")){
            System.out.println("用户 yc 存在，登陆成功");
        }
        else {
            System.out.println("用户 yc 不存在，登陆失败");
        }
        //注册新用户
        if (new registerUserServiceimpl().registerUser("yc","123456","666666")){
            System.out.println("注册新用户 yc 成功");
        }
        else {
            System.out.println("该用户已存在，注册失败");
        }
        //测试登录
        if (new loginUserServiceimpl().loginUserService("yc","123456")){
            System.out.println("用户 yc 存在，登陆成功");
        }
        else {
            System.out.println("用户不存在，登陆失败");
        }

        //
        System.out.println("已经存在三个行程，最大行程id为3，观察是否成功");
        judgeJourneyServiceimpl judgeJourneyServiceimpl= new judgeJourneyServiceimpl();
        Journey Journey=judgeJourneyServiceimpl.judgeJourneyService(3);
        System.out.print("id 为 3 的订单"+Journey.toString());
        System.out.println("\n");

        System.out.println("发布新的行程，按道理 id 应该为4");
        Date d1 = new Date(2014-1900, 6-1, 12);
        Journey journey = new launchJourneyServiceimpl().launchJourney(d1,"kungong","chenggong","123");

        Journey Journey1=judgeJourneyServiceimpl.judgeJourneyService(4);
        System.out.print("数据库查询 id 为 4 的订单"+Journey1.toString());
        System.out.println("\n");




    }


    @Test
    public void Test() {
        double[] myList = {1.9, 2.9, 3.4, 3.5};

        // 打印所有数组元素
        for (int i = 0; i < myList.length; i++) {
            System.out.println(myList[i] + " ");
        }

    }





}
